
package com.android.formula.common;

import android.app.Application;
import android.content.Context;

import com.android.formula.database.NoteDatabaseConnection;
import com.android.formula.database.SQLiteTable;

public class MyApplication extends Application {
    private static boolean mIsBuildDebug = false;

    // Variables
    // ---------------------------------------------------------------------------------->
    public static Context mContext = null;

    private static String mAppVersion = "";

    private static NoteDatabaseConnection mNoteDatabaseConnection = null;

    private static SQLiteTable mSqLiteTable = null;
    
    public static final int API_VERSION = android.os.Build.VERSION.SDK_INT;

    // Get / Set
    // ---------------------------------------------------------------------------------->

    public static boolean isBuildDebug() {
        return mIsBuildDebug;
    }

    public static String getAppVersion() {
        return mAppVersion;
    }

    public static Context getContext() {
        return mContext;
    }

    public static NoteDatabaseConnection getDatabaseConnection() {
        return mNoteDatabaseConnection;
    }

    public static SQLiteTable getSqLiteTable() {
        return mSqLiteTable;
    }

    // Init ---------------------------------------->
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        mNoteDatabaseConnection = new NoteDatabaseConnection(mContext);
        mNoteDatabaseConnection.createDatabase();
        mSqLiteTable = new SQLiteTable(mContext);
        mSqLiteTable.createDatabase();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        if (mNoteDatabaseConnection != null) {
        	mNoteDatabaseConnection.close();
        }
        if (mSqLiteTable != null) {
            mSqLiteTable.close();
        }
    }

}
